package model.feature;

import java.io.File;

import model.Settings;
import model.inventory.FieldFormatMapper;
import util.PlayerUtilities;


public class FeatureDefinitionBackup {
	private static FeatureDefinitionBackup _instance;

	private FeatureType featureType = FeatureType.WEATHER;
	private int 		numberOfDaysToPlay	=	-1;
	private int 		containerID			=	-1;
	private int			orientation; // 0 Horizontal, 1 vertical
	private FieldFormatMapper textFormatMapper;
	
	public enum FeatureType {
		WEATHER, DATE
	}

	public static FeatureDefinitionBackup getInstance() {
		// load inventory player from XML file if the data file exists.
		if (_instance == null) {
			File definitionFile = new File(Settings.FEATURE_DEF_XML);
			if (definitionFile.exists()) {
				Object obj = PlayerUtilities.getObjectFromXMLFile(Settings.FEATURE_DEF_XML);
				if (obj instanceof FeatureDefinitionBackup) {
					_instance = (FeatureDefinitionBackup) obj;
					return _instance;
				}
			}
			_instance = new FeatureDefinitionBackup();
		}
		return _instance;
	}

	public void saveToXML() {
		PlayerUtilities.saveObjectToXMLFile(Settings.FEATURE_DEF_XML, this);
	}

	private FeatureDefinitionBackup() {
		this.reset();
	}

	public FeatureType getFeatureType() {
		return featureType;
	}
	
	public void setFeatureType(FeatureType featureType) {
		this.featureType = featureType;
	}

	public void reset() {
		System.out.println("Reseting features definition");
		featureType = FeatureType.WEATHER;
		
		numberOfDaysToPlay 	= -1;
		orientation 		= -1;
		containerID 		= -1;
	}

	public int getNumberOfDaysToPlay() {
		return numberOfDaysToPlay;
	}

	public void setNumberOfDaysToPlay(int numberOfDaysToPlay) {
		this.numberOfDaysToPlay = numberOfDaysToPlay;
	}

	public int getContainerID() {
		return containerID;
	}

	public void setContainerID(int containerID) {
		this.containerID = containerID;
	}

	
	public int getOrientation() {
		return orientation;
	}

	public void setOrientation(int orientation) {
		this.orientation = orientation;
	}

	public FieldFormatMapper getTextFormatMapper() {
		return textFormatMapper;
	}

	public void setTextFormatMapper(FieldFormatMapper textFormatMapper) {
		this.textFormatMapper = textFormatMapper;
	}
	
	@Override
	public String toString() {
		return "FeatureDefinition [containerID=" + containerID
				+ ", featureType=" + featureType + ", numberOfDaysToPlay="
				+ numberOfDaysToPlay + ", orientation=" + orientation
				+ ", textFormatMapper=" + textFormatMapper + "]";
	}

	public static void main(String[] args) {
		FeatureDefinitionBackup obj = FeatureDefinitionBackup.getInstance();
		System.out.println(obj.getTextFormatMapper().get("option1"));
	}
	
}
